package com.gem.sms.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class AdminInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 判断用户是否登录,如果登录了,则显示列表数据,如果没登录,重回登录页面
        HttpSession session = request.getSession();
        Object obj = session.getAttribute("student");
        if (obj == null) {
            // 说明没有登录!
            response.sendRedirect(request.getContextPath() + "/stu/index?info=2");
            System.out.println("未登录");
            return false;
        } else {
            System.out.println("登录");
           return true;
        }
    }
}
